//
//  CompereHepler.m
//  JZMCFM
//
//  Created by Mc on 15/10/31.
//  Copyright (c) 2015年 陈卓. All rights reserved.
//

#import "CompereHepler.h"
#import "CompereModel.h"
@implementation CompereHepler

+ (instancetype)sharedInstance
{
    static CompereHepler *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[CompereHepler alloc] init];
    });
    return manager;
}


- (void)downLoadWithResultBlock:(ResultBlock)resultBlock
{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [SVProgressHUD showWithStatus:@"数据加载" maskType:SVProgressHUDMaskTypeBlack];
        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        manager.requestSerializer = [AFJSONRequestSerializer serializer];
        [manager GET:kCompereUrl parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSMutableArray *listArray = responseObject[@"list"];
            for (NSDictionary *dict in listArray) {
                CompereModel *p = [[CompereModel alloc] init];
                p.title = dict[@"title"];
                p.name = dict[@"name"];
                NSArray *listImage = dict[@"list"];
                for (NSDictionary *dict1 in listImage) {
                    [p setValuesForKeysWithDictionary:dict1];
                    [self.modelArray addObject:p];
                    
                }
                
                p.listImage = listImage;
                [self.compereArray addObject:p];
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                resultBlock();
            });
            [SVProgressHUD showErrorWithStatus:@"数据加载成功" duration:1.0];
            
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"%@",error);
        }];
        
    });
}

- (NSMutableArray *)compereArray
{
    if (!_compereArray) {
        _compereArray = [NSMutableArray array];
    }
    return _compereArray;
}

- (NSMutableArray *)modelArray
{
    if (!_modelArray) {
        _modelArray = [NSMutableArray array];
    }
    return _modelArray;
}
@end
